package com.sskj.asset.ui.activity;


import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bulong.rudeness.RudenessScreenHelper;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.asset.R;
import com.sskj.asset.R2;
import com.sskj.asset.bean.ExchangeHistoryEntry;
import com.sskj.asset.presenter.CashRecordActivityPresenter;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

@Route(path = RConfig.ASSET_CASH_RECORD)//兑换记录
public class CashRecordActivity extends BaseActivity<CashRecordActivityPresenter> {
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;

    @Override
    protected int getLayoutId() {
        return R.layout.asset_activity_cash_record;
    }

    @Override
    public CashRecordActivityPresenter getPresenter() {
        return new CashRecordActivityPresenter();
    }

    @Override
    protected void initView() {
        setTitle(App.INSTANCE.getString(R.string.asset_cashRecordActivity1_j));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(App.INSTANCE, 20))
                .setDividerColor(ContextCompat.getColor(App.INSTANCE, R.color.transparent))
        );
        SlimAdapter slimAdapter = SlimAdapter.create().register(R.layout.asset_recy_item_cash_record, new SlimInjector<ExchangeHistoryEntry.Entry>() {
            @Override
            public void onInject(ExchangeHistoryEntry.Entry data, IViewInjector injector, List payloads) {
                injector.text(R.id.title, String.format("%s兑换%s", data.getBname(), data.getPname()))
                        .text(R.id.time, data.getAddtime())
                        .text(R.id.exchange_num, data.getBnums() + data.getBname())
                        .text(R.id.exchange_get, data.getPnums() + data.getPname())
                ;
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        ModelRx2DataSource<ExchangeHistoryEntry.Entry> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<ExchangeHistoryEntry.Entry>)
                page -> mPresenter.getHistory(page, 20), 20);
        MVCCoolHelper<List<ExchangeHistoryEntry.Entry>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }

    @Override
    protected void initData() {
    }


}
